class ConfigParser
{

	// a small subset of the Python ConfigParser.
	// supports files in exactly this format:
	// [header]
	// name=data
	// ....
	// Data is returned as a string in a two-layer string hash:
	// first the header, than the name.
	//
	// no placeholder variables, colon syntax or other nifty stuff. Sorry!

	// "==" in data entries will cause the data side to return
	// an empty string.

	public static function main()
	{
		var z = read("[Test]\n"+
			 " num=200   \n"+
			 "rqiqope=trtsdvse\nweww=dooo\n"+
			 "[Another]\n"
			 +"nedo=doeo");
		trace(z.keys());
		trace("hi w");
		trace(z.get("Test").toString());
		trace(z.get("Another").toString());
	}

	public static function read(input : String) : Hash<Hash<String>>
	{
		var splitted = input.split("\n");
		var sections = new Hash<Hash<String>>();
		var cur : Hash<String>;
		var curname : String;
		
		for (s in splitted)
		{
			var clean = StringTools.trim(s);
			var eq = clean.indexOf("=");
			if (StringTools.startsWith(clean,"[") && StringTools.endsWith(clean,"]"))
			{
				cur = new Hash<String>();
				curname = clean.substr(1,clean.length-2);
				sections.set(curname,cur);
			}
			else if (eq>-1)
			{
				var combi = clean.split("=");
				cur.set(combi[0],combi[1]);
			}
		}

		return sections;
		
	}

}
